// pages/u_tx/u_tx.js
const app = getApp()
var get_user;var save_user_tx;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    money:'0.00',
    name:null,
    card:'',
    card_mobile:'',
    yh:'',
    zh:'',
    price:'',
  },
  pricetap:function(e){
    this.setData({
      price:e.detail.value
    })
  },
  alltap:function(e){
    this.setData({
      price:this.data.money
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    get_user = app.data.ucenter_url + 'get_user';
    save_user_tx = app.data.ucenter_url + 'save_user_tx';
  },
  addtap:function(e){
    wx.navigateTo({
      url: '/pages/u_addbank/u_addbank',
    })
  },
  submit:function(e){
    var that = this;
    var name = that.data.name;
    var price = that.data.price;
    var money = that.data.money;
    if(name == null){
      wx.showModal({
        title: '提示',
        content: '请先添加银行卡',
        showCancel: false
      })
    }else if(price == ''){
      wx.showModal({
        title: '提示',
        content: '请输入提现金额',
        showCancel: false
      })
    }else if(Number(price) < 0.1){
      wx.showModal({
        title: '提示',
        content: '输入提现金额必须大于0元',
        showCancel: false
      })
    }else if(Number(price) > Number(money)){
      wx.showModal({
        title: '提示',
        content: '提现金额不可大于可提金额',
        showCancel: false
      })
    }else{
      wx.showLoading();
      var aid = wx.getStorageSync('uid');
      wx.request({
        url: save_user_tx,
        data: {
          uid:aid,
          price:price
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        success (res) {
          console.log(res.data);
          wx.hideLoading();
          if(res.data.state == 1){
            wx.showModal({
              title: '提示',
              content: '提交成功，请等待审核通过！',
              showCancel: false,
              success:function(e){
                wx.switchTab({
                  url: '/pages/ucenter/ucenter',
                })
              }
            })
          }
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    var aid = wx.getStorageSync('uid');
    wx.request({
      url: get_user,
      data: {
        uid: aid
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        console.log(res.data);
        var info = res.data.info;
        var money = info.money;
        var name = info.name;
        var card = info.card;
        var card_mobile = info.card_mobile;
        var yh = info.yh;
        var zh = info.zh;
        that.setData({
          money:money,
          name:name,
          card:card,
          card_mobile:card_mobile,
          yh:yh,
          zh:zh
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})